<template>
	<view>
		<cu-custom bgColor="bg-gradual-fff" isBack="true">
			<block slot="content">会员核销</block>
		</cu-custom>
		<loading-view v-if="showLoading"></loading-view>
		<view class="layout" v-show="!showLoading">
			<view class="viewbox"></view>
			<view class="user_writeoff_a_b">
				用户名：{{UserDetail.nickname}}----------电话：{{UserDetail.mobile}}
			</view>

			<view class="user_writeoff_b_b">
				<input style="background: #d2e9ef; width: 100%; height: 100%; 
				padding-left: 30rpx;" type="number" v-model="amount" placeholder="输入金额"></input>
			</view>
			<view class="user_writeoff_ab" @click="handleVerificationConfirm">点击核销</view>
		</view>
	</view>
</template>
<script>
	import api from '../../common/apiService';
	import request from '../../common/request';
	const {
		getUserIntegral
	} = api;

	import {
		loadingType
	} from '@/utils/type';
	export default {
		data() {
			return {
				UserDetail: [],
				amount: 0,
				uid: 0,
				mid:0
			}
		},
		onLoad() {
			const mid = uni.getStorageSync('mid');
			
			this.mid = mid
			console.log("mid为",mid)
			this.uid = uni.getStorageSync('uid');
			this.loginfo();
		},
		onShow() {},
		methods: {
			// 获取用户信息
			loginfo() {
				const uid = uni.getStorageSync('uid');
				getUserIntegral(uid).then(res => {
					this.UserDetail = res;
					console.log("得到的用户信息", this.UserDetail);
				}).catch(e => {
					console.log("另一个信息", e);
				})
			},
			handleVerificationConfirm() {
				uni.request({
					url: request.baseUrl + 'm-ConfirmScan',
					method: 'POST',
					header: {
						'Content-Type': 'application/json'
					},
					data: {
						mid: this.mid,
						uid: this.uid,
						amount: this.amount
					},
					success(res) {
						console.log("得到",res)
						
						if(res.data.code===200){
							uni.showToast({
								title:res.data.data.msg,
								icon:'success'
							}).then(()=>{
								setTimeout(()=>{
									uni.redirectTo({
										url:'/pages/index/index'
									})
								},1500)
							}).finally(()=>{
								uni.removeStorageSync('uid');
							})
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'error'
							}).then(()=>{
								setTimeout(()=>{
									uni.redirectTo({
										url:'/pages/index/index'
									})
								},1500)
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.layout {
		.user_writeoff_a_b {
			width: 710rpx;
			height: 100rpx;
			// border: 1px solid red;
			margin: 100rpx 20rpx 0 20rpx;
			font-size: 25rpx;
			color: #000000;
			font-weight: 600;
			box-sizing: border-box;
			border-radius: 20rpx;
			background: #ffffff;
			padding: 30rpx 0 0 100rpx;
		}

		.user_writeoff_b_b {
			width: 710rpx;
			height: 100rpx;
			// border: 1px solid red;
			border-radius: 40rpx;
			margin: 50rpx 20rpx 0 20rpx;
		}

		.user_writeoff_ab {
			width: 300rpx;
			height: 120rpx;
			margin: 50rpx 0 0 250rpx;
			// border: 1px solid red;
			border-radius: 30rpx;
			background: rgba(110, 173, 255, 0.5);
			font-size: 30rpx;
			font-weight: 500;
			box-sizing: border-box;
			padding: 40rpx 0 0 90rpx;
		}

	}
</style>